let baseUrl = 'http://127.0.0.1:3000'

let request = (url,method='GET',data)=>{
	return new Promise((resolve, reject)=>{
		uni.request({
			url:baseUrl + url, 
			method: method,
			data,
			header: {
				'content-type': 'application/json', //自定义请求头信息
				"Authorization": uni.getStorageSync("TOKEN")
			},
			success: (res) => {
				if(res.data.code == 200){
					resolve(res.data.data)
				}else{
					uni.showToast({
						icon: "none",
						title: res.data.message
					});
					reject(res.data.message);
				}
			},
			fail(err) {
				uni.showToast({
					icon: "none",
					title: '服务响应失败'
				});
				reject(err);
			},
			complete() {
				uni.hideLoading();
			}
		});
	})
}

export {request};